package com.zsc.newbuds.mapper;

import com.zsc.newbuds.entity.ExchangeRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author D
 */
public interface ExchangeRecordMapper {

    /**
     * 查詢所有兌換記錄
     * @return
     */
    @Select("select * from exchangeRecord")
    List<ExchangeRecord> getExchangeRecordList();

    /**
     * 查詢用户兌換記錄
     * @param userId
     * @return
     */
    @Select("select * from exchangeRecord where user_id = #{userId}")
    List<ExchangeRecord> getUserExchangeRecordList(Integer userId);

    /**增加用戶兌換記錄
     * @param exchangeRecord
     */
    @Options(useGeneratedKeys = true,keyProperty = "exchangeId")
    @Insert("insert into exchangeRecord(goods_id,user_id,goods_name,goods_price,goods_image) values(#{goodsId},#{userId},#{goodsName},#{goodsPrice},#{goodsImage})")
    void addExchangeRecord(ExchangeRecord exchangeRecord);

    /**
     * 更新订单号
     * @param id
     * @param no
     */
    @Update("update exchangeRecord set tracking_number = #{no} where exchange_id = #{id}")
    void updateNo(Integer id,String no);
}
